package com.lyk.coursearrange.controller;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.lyk.coursearrange.common.core.base.code.CodeEnum;
import com.lyk.coursearrange.common.core.base.result.R;

import com.lyk.coursearrange.common.exception.MZException;
import com.lyk.coursearrange.common.log.annotation.Log;
import com.lyk.coursearrange.common.log.enums.OperationType;
import com.lyk.coursearrange.common.utils.StringUtils;
import com.lyk.coursearrange.dao.SourcePeopleDao;
import com.lyk.coursearrange.dao.TeacherDao;
import com.lyk.coursearrange.domain.SysTestLinux;
import com.lyk.coursearrange.domain.SysZhengshiLinux;
import com.lyk.coursearrange.entity.CustomerInformation;

import com.lyk.coursearrange.entity.Stages;
import com.lyk.coursearrange.entity.Student;
import com.lyk.coursearrange.entity.TeachStuInfo;
import com.lyk.coursearrange.entity.dto.CustomerInformationDO2;
import com.lyk.coursearrange.entity.dto.CustomerInformationDto;

import com.lyk.coursearrange.entity.dto.CustomerInformationDtoTwo;
import com.lyk.coursearrange.excel.ExcelCustomerInformationOutData;
import com.lyk.coursearrange.service.CustomerInformationService;
import com.lyk.coursearrange.service.SourcePeopleService;
import com.lyk.coursearrange.service.SourceService;
import com.lyk.coursearrange.service.StudentService;
import com.lyk.coursearrange.util.ExcelUtil;
import com.lyk.coursearrange.util.FtpUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author lequal
 * @since 2020-04-15
 */
@RestController
@Slf4j
@RequestMapping("/customerinformation")
public class CustomerInformationController {
    //文件上传的地址变量
    String customer_url;
    String customer_ewm;


    @Autowired
    private CustomerInformationService customerInformationService;
    @Autowired
    private TeacherDao teacherDao;
    @Autowired
    private SourceService sourceService;
    @Autowired
    private SourcePeopleService sourcePeopleService;
    @Autowired
    private StudentService studentService;
//    @Autowired
//    private Object Installment;

    //测试
    @Autowired
    private SourcePeopleDao sourcePeopleDao;


    public void isAllPay(CustomerInformationDO2 customerInformation) {
        // 分期
        if (customerInformation.getIsAllPay() != null && customerInformation.getIsAllPay() == 2) {
            for (Stages stage : customerInformation.getStages()) {
                sourcePeopleDao.insertstages(stage);
                sourcePeopleDao.insertcustomerasstages(customerInformation.getCustomerInformationId(), stage.getStagesId());
            }
        } else {
            sourcePeopleDao.deletebycustomeridone(customerInformation.getCustomerInformationId());
            sourcePeopleDao.deletebycustomeridtwo(customerInformation.getCustomerInformationId());
        }
    }


    @PostMapping("upSaves")
    @Transactional
    @Log(title = "诊断这块", operationType = OperationType.OTHER)
    public R<CustomerInformation> upSaves(@RequestBody CustomerInformationDO2 dto) {
            CustomerInformation byId = customerInformationService.getById(dto.getCustomerInformationId());
            if (byId.getType().equals(1)) {
                if (dto.getIsDiagnosisAllPay() == 2) {//诊断费
                    return R.error("诊断不能为空");
                }
            } else if (byId.getType().equals(2)) {
                if (dto.getIsAllPay() == null) {//尾款费用
                    return R.error("尾款不能为空");
                }
            }


            // 尾款分期
            if (dto.getIsAllPay() != null && dto.getIsAllPay() == 2) {
                for (Stages stage : dto.getStages()) {
                    if (StringUtils.isEmpty(stage.getStagesDate()) || stage.getPayType() == null || StringUtils.isEmpty(stage.getStagesMoney())) {
                        return R.error("表格不完善");
                    }
                }
            }


            Student student;
            if (StringUtils.isBlank(byId.getCustomerStudent())) {
                student = Student.builder()
                        .studentNo(System.currentTimeMillis() + " ")
                        .password("123456")
                        .username(dto.getStudentName())
                        .realname(dto.getStudentName())
                        .userType(3)
                        .grade(dto.getGrade()[1])
                        .sex(dto.getSex())
                        .address(dto.getAddress()).build();
                studentService.save(student);
            } else {
                student = Student.builder()
                        .id(byId.getStudentId())
                        .username(dto.getStudentName())
                        .grade(dto.getGrade()[1])
                        .sex(dto.getSex())
                        .address(dto.getAddress()).build();
                studentService.updateById(student);
            }

            //先执行删除
            sourcePeopleDao.deletebycustomeridone(dto.getCustomerInformationId());
            sourcePeopleDao.deletebycustomeridtwo(dto.getCustomerInformationId());
            isAllPay(dto);

            CustomerInformation customerInformation = new CustomerInformation();
            customerInformation.setCustomerId(dto.getCustomerInformationId());


            customerInformation.setCustomerIspay(dto.getIsDiagnosisAllPay());//是否交诊断费
            if (dto.getIsDiagnosisAllPay() != null && dto.getIsDiagnosisAllPay() == 1) {
                customerInformation.setCustomerPaymoney(dto.getDiagnosisAllPayMoney());//诊断费用
                customerInformation.setCustomerPaytime(dto.getDiagnosisTime());//付款时间
                customerInformation.setPayType(dto.getDiagnosisPayType());//支付渠道[1-现金，2-微信，3-支付宝]
            } else {
                customerInformation.setCustomerPaymoney(null);
                customerInformation.setCustomerPaytime(null);
                customerInformation.setPayType(null);
            }


            customerInformation.setCustomerIsallpay(dto.getIsAllPay()); //是否交全款
            if (dto.getIsAllPay() != null && dto.getIsAllPay() == 1) {
                customerInformation.setCustomerAllpaymoney(dto.getAllPayMoney());//全款费用}
                customerInformation.setCustomerAllpaytime(dto.getPayTime());//付款时间
                customerInformation.setPayAlltype(dto.getPayType());//支付渠道[1-现金，2-微信，3-支付宝]
            } else {
                customerInformation.setCustomerAllpaymoney(null);//全款费用
                customerInformation.setCustomerAllpaytime(null);//付款时间
                customerInformation.setPayAlltype(null);//支付渠道[1-现金，2-微信，3-支付宝]
            }

            if (StringUtils.isNotEmpty(dto.getStartTime())) {
                String StartTimeStr = JSON.toJSONString(dto.getStartTime());
                customerInformation.setStartTime(StartTimeStr);//授课时间
            }

            customerInformation.setParentPhoneNumber(dto.getParentPhoneNumber());
            customerInformation.setStudentId(student.getId());
            customerInformation.setCustomerStudent(dto.getStudentName());
            customerInformation.setCategoryId(dto.getCourseCategoryId()[dto.getCourseCategoryId().length - 1]);
            customerInformation.setCustomerTeacherid(Long.valueOf(dto.getTeacherId()));
            customerInformation.setType(2);
            customerInformation.setIsSubmit(1);
            customerInformationService.updateById(customerInformation);

        return R.ok();


    }

    @Deprecated
    @PostMapping("upSavesOld")
    @Transactional
    @Log(title = "诊断这块", operationType = OperationType.OTHER)
    public R<CustomerInformation> upSavesOld(@RequestBody CustomerInformationDO2 dto) {
        Student student = Student.builder()
                .studentNo(System.currentTimeMillis() + " ")
                .password("123456")
                .username(dto.getStudentName())
                .realname(dto.getStudentName())
                .userType(3)
                .grade(dto.getGrade()[1])
                .sex(dto.getSex())
                .address(dto.getAddress()).build();
        studentService.save(student);


        // 交了诊断费
//        if (customerInformation.getCustomerIspay().equals(1)) {
//            if (customerInformation.getCustomerPaymoney() == null) {
//                return R.error("诊断费金额不能为空");
//            }
//            if (customerInformation.getCustomerPaytime() == null) {
//                return R.error("诊断时间不能为空");
//            }
//            if (customerInformation.getPayType() == null) {
//                return R.error("支付渠道不能为空");
//            }
//        }
        // 尾款分期
        if (dto.getIsAllPay() == 2) {
            for (Stages stage : dto.getStages()) {
                if (StringUtils.isEmpty(stage.getStagesDate()) || stage.getPayType() == null || StringUtils.isEmpty(stage.getStagesMoney())) {
                    return R.error("表格不完善");
                }
            }
        }
        isAllPay(dto);

        CustomerInformation customerInformation = new CustomerInformation();
        customerInformation.setCustomerId(dto.getCustomerInformationId());

        customerInformation.setCustomerIspay(dto.getIsDiagnosisAllPay());//是否交诊断费
        if (dto.getIsDiagnosisAllPay() == 1) {
            customerInformation.setCustomerPaymoney(dto.getDiagnosisAllPayMoney());//诊断费用
            customerInformation.setCustomerPaytime(dto.getDiagnosisTime());//付款时间
            customerInformation.setPayType(dto.getDiagnosisPayType());//支付渠道[1-现金，2-微信，3-支付宝]
        }

        customerInformation.setCustomerIsallpay(dto.getIsAllPay()); //是否交全款
        if (dto.getIsAllPay() == 1) {
            customerInformation.setCustomerAllpaymoney(dto.getAllPayMoney());//全款费用}
            customerInformation.setCustomerAllpaytime(dto.getPayTime());//付款时间
            customerInformation.setPayAlltype(dto.getPayType());//支付渠道[1-现金，2-微信，3-支付宝]
        }
        String StartTimeStr = JSON.toJSONString(dto.getStartTime());
        customerInformation.setStartTime(StartTimeStr);//授课时间

        customerInformation.setCustomerStudent(dto.getStudentName());
        customerInformation.setStudentId(student.getId());
        customerInformation.setCategoryId(dto.getCourseCategoryId()[1]);
        customerInformation.setType(2);
        customerInformation.setIsSubmit(2);
        customerInformationService.updateById(customerInformation);

        return R.ok();
    }


    @Deprecated
    @PutMapping("editOneOld")
    @Transactional
    @Log(title = "诊断这块", operationType = OperationType.OTHER)
    public R<CustomerInformation> editOneOld(@RequestBody CustomerInformationDO2 dto) {
        CustomerInformation byId = customerInformationService.getById(dto.getCustomerInformationId());
//        if (byId.getIsSubmit() == 1) {
//            return R.error("该客资已提交");
//        }

        Student student = Student.builder()
                .id(byId.getStudentId())
                .username(dto.getStudentName())
                .grade(dto.getGrade()[1])
                .sex(dto.getSex())
                .address(dto.getAddress()).build();
        studentService.updateById(student);


        // 交了诊断费
//        if (customerInformation.getCustomerIspay().equals(1)) {
//            if (customerInformation.getCustomerPaymoney() == null) {
//                return R.error("诊断费金额不能为空");
//            }
//            if (customerInformation.getCustomerPaytime() == null) {
//                return R.error("诊断时间不能为空");
//            }
//            if (customerInformation.getPayType() == null) {
//                return R.error("支付渠道不能为空");
//            }
//        }

        //先执行删除
        sourcePeopleDao.deletebycustomeridone(dto.getCustomerInformationId());
        sourcePeopleDao.deletebycustomeridtwo(dto.getCustomerInformationId());
        // 尾款分期
        if (dto.getIsAllPay() == 2) {
            for (Stages stage : dto.getStages()) {
                if (StringUtils.isEmpty(stage.getStagesDate()) || stage.getPayType() == null || StringUtils.isEmpty(stage.getStagesMoney())) {
                    return R.error("表格不完善");
                }
            }
        }
        isAllPay(dto);

        CustomerInformation customerInformation = new CustomerInformation();
        customerInformation.setCustomerId(dto.getCustomerInformationId());

        customerInformation.setCustomerIspay(dto.getIsDiagnosisAllPay());//是否交诊断费
        if (dto.getIsDiagnosisAllPay() == 1) {
            customerInformation.setCustomerPaymoney(dto.getDiagnosisAllPayMoney());//诊断费用
            customerInformation.setCustomerPaytime(dto.getDiagnosisTime());//付款时间
            customerInformation.setPayType(dto.getDiagnosisPayType());//支付渠道[1-现金，2-微信，3-支付宝]
        } else {
            customerInformation.setCustomerPaymoney(null);
            customerInformation.setCustomerPaytime(null);
            customerInformation.setPayType(null);
        }


        customerInformation.setCustomerIsallpay(dto.getIsAllPay()); //是否交全款
        if (dto.getIsAllPay() == 1) {
            customerInformation.setCustomerAllpaymoney(dto.getAllPayMoney());//全款费用
            customerInformation.setCustomerAllpaytime(dto.getPayTime());//付款时间
            customerInformation.setPayAlltype(dto.getPayType());//支付渠道[1-现金，2-微信，3-支付宝]
        } else {
            customerInformation.setCustomerAllpaymoney(null);//全款费用
            customerInformation.setCustomerAllpaytime(null);//付款时间
            customerInformation.setPayAlltype(null);//支付渠道[1-现金，2-微信，3-支付宝]
        }

        String StartTimeStr = JSON.toJSONString(dto.getStartTime());
        customerInformation.setStartTime(StartTimeStr);//授课时间

        customerInformation.setCustomerStudent(dto.getStudentName());
        customerInformation.setCategoryId(dto.getCourseCategoryId()[1]);
        customerInformation.setCustomerTeacherid(Long.valueOf(dto.getTeacherId()));
        customerInformation.setType(2);
        customerInformation.setIsSubmit(1);
        customerInformationService.updateById(customerInformation);
        return R.ok();
    }


    @GetMapping("getOne/{id}")
    @Log(title = "诊断这块", operationType = OperationType.SELECT)
    public R<CustomerInformation> getOne(@PathVariable("id") Long id) {
        CustomerInformation byId = customerInformationService.getById(id);

        if (byId.getGradeIdArr() != null) {
            int[] array1 = Arrays.stream(byId.getGradeIdArr().split(",")).mapToInt(Integer::parseInt).toArray();
            byId.setGradeIdArr2(array1);
        }
        if (byId.getCategoryIdArr() != null) {
            int[] array2 = Arrays.stream(byId.getCategoryIdArr().split(",")).mapToInt(Integer::parseInt).toArray();
            byId.setCategoryIdArr2(array2);
        }

//        String[] array3 = byId.getGradeIdArrToStr().split(",");
//        String[] array4 = byId.getCategoryIdArrToStr().split(",");


//        byId.setGradeIdArrToStr2(array3);
//        byId.setCategoryIdArrToStr2(array4);
        List<Stages> selectStages = sourcePeopleDao.selectstages(byId.getCustomerId());
        if (selectStages.size() > 0) {
            if (byId.getCustomerIsallpay() == 2) {
                byId.setStages(selectStages);
            }
        }

        return R.ok().data("list", byId);
    }


    /**
     * 查询客资接口
     */
    @ApiOperation(value = "查询客资接口", notes = "查询客资接口")
    @PostMapping("customerinformationlist")
    @Log(title = "分页查询客资列表", operationType = OperationType.SELECT)
    public R customerinformationlist(@RequestBody Map<String, String> param) throws MZException {
        List<CustomerInformation> list = customerInformationService.customerinformationlist(param);
        Long count = customerInformationService.customerinformationcount(param);
        List<CustomerInformationDto> customerInformationDtos = new ArrayList<>();
        list.forEach(customerInformation -> {
            customerInformationDtos.add(CustomerInformationDto.builder()
                    .customerId(Long.valueOf(customerInformation.getCustomerId()))
                    .customerWx(customerInformation.getCustomerWx())
                    .customerSource(customerInformation.getCustomerSource())
                    .sourceName(customerInformationService.getsourcename(customerInformation.getCustomerSource()))
                    .customerSourcepeople(customerInformation.getCustomerSourcepeople())
                    .sourcepeopleName(customerInformationService.getsourcepeoplename(customerInformation.getCustomerSourcepeople()))
                    .customerUrl(customerInformation.getCustomerUrl())
                    .customerTeacherid(customerInformation.getCustomerTeacherid())
                    .customerTeacherName(teacherDao.getteacherName(customerInformation.getCustomerTeacherid()))
                    .customerStudent(customerInformation.getCustomerStudent())
                    .customerState(customerInformation.getCustomerState())
                    .customerAccount(customerInformation.getCustomerAccount())
                    .customerEwm(customerInformation.getCustomerEwm())
                    .customerIsactive(customerInformation.getCustomerIsactive())
                    .type(customerInformation.getType())
                    .parentPhoneNumber(customerInformation.getParentPhoneNumber())
                    .createTime(customerInformation.getCreateTime())
                    .updateTime(customerInformation.getUpdateTime())
                    .build());
        });
        return R.ok()
                .data("list", customerInformationDtos)
                .data("count", count)
                .message("查询教资接口成功");
    }

//    private boolean hasInstallments(Long customerFullPaymentAmount) {
//        return
//    }
//
//    private boolean isFullPayment(Boolean customerFullPaymentAmount) {
//
//        return customerFullPaymentAmount;
//    }


    /**
     * 添加客资接口
     */
    @ApiOperation(value = "添加客资接口", notes = "添加客资接口")
    @PostMapping(path = "/customerinformationadd")
    @Log(title = "添加客资接口", operationType = OperationType.INSERT)
    public R customerinformationadd(@RequestBody Map<String, String> param) throws MZException {
        param.put("customer_url", customer_url);
        param.put("customer_ewm", customer_ewm);
        boolean a = customerInformationService.customerinformationadd(param);
        if (a) {
            customer_url = null;
            customer_ewm = null;
            return R.ok().message("客资信息添加成功");
        } else {
            throw new MZException(CodeEnum.CUSTOMER_ADD);
        }
    }

    /**
     * 查询客资来源接口
     */
    @ApiOperation(value = "查询客资来源接口", notes = "查询客资来源接口")
    @GetMapping("sourcelist")
/*    @Log(title = "查询客资来源接口", operationType = OperationType.SELECT)*/
    public R sourcelist() throws MZException {
        return R.ok().data("list", sourceService.sourcelist()).message("查询客资来源成功");
    }

    /**
     * 查询客资来源负责人接口
     */
    @ApiOperation(value = "查询客资来源负责人接口", notes = "查询客资来源负责人接口")
    @GetMapping("sourcepeoplelist")
   /* @Log(title = "查询客资来源负责人接口", operationType = OperationType.SELECT)*/
    public R sourcepeoplelist() throws MZException {
        return R.ok().data("list", sourcePeopleService.sourcepeoplelist()).message("查询客资来源负责人成功!!");
    }


    /**
     * 修改教资状态接口
     */

    @ApiOperation(value = "修改教资状态接口", notes = "修改教资状态接口")
    @PutMapping("customerstateupdate")
    @Log(title = "修改教资状态接口", operationType = OperationType.UPDATE)
    public R customerstateupdate(@RequestBody Map<String, String> param) throws MZException {
        boolean a = customerInformationService.customerstateupdate(param);
        if (a) {
            return R.ok().message("修改教资状态成功!!");
        } else {
            throw new MZException(CodeEnum.Customer_State_Update);
        }
    }


    /**
     * 修改教资状态接口
     */

    @ApiOperation(value = "修改教资主动被动接口", notes = "修改教资主动被动接口")
    @PutMapping("customerisactiveupdate")
    @Log(title = "修改教资状态接口", operationType = OperationType.UPDATE)
    public R customerisactiveupdate(@RequestBody Map<String, String> param) throws MZException {
        boolean a = customerInformationService.customerisactiveupdate(param);
        if (a) {
            return R.ok().message("修改修改教资主动被动成功!!");
        } else {
            throw new MZException(CodeEnum.Customer_State_Update);
        }
    }


    /**
     * 删除教资信息接口
     */

    @ApiOperation(value = "删除教资信息接口", notes = "删除教资信息接口")
    @DeleteMapping("customerdelete/{customer_id}")
    @Log(title = "删除教资信息接口", operationType = OperationType.DELETE)
    public R customerdelete(@PathVariable Long customer_id) throws MZException {
        int a = customerInformationService.customerdelete(customer_id);
        if (a > 0) {
            return R.ok().message("删除教资信息成功!!");
        } else {
            throw new MZException(CodeEnum.Customer_State_Delete);
        }
    }


    /**
     * 客资截图上传接口
     */
    @PostMapping(value = "/importFile")
    @Log(title = "客资截图上传接口", operationType = OperationType.OTHER)
    public R importFile(@RequestParam("file") MultipartFile file) throws Exception {
        File toFile = null;
        if (file.equals("") || file.getSize() <= 0) {
            file = null;
        } else {
            InputStream ins = null;
            ins = file.getInputStream();
            toFile = new File(file.getOriginalFilename());
            inputStreamToFile(ins, toFile);

            ins.close();
        }
        if (file.isEmpty()) {
            return R.error().message("文件为空");
        }
        String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        FileInputStream fileInputStream = new FileInputStream(toFile);
        BufferedInputStream in = new BufferedInputStream(fileInputStream);
        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
        byte[] temp = new byte[1024];
        int size = 0;
        while ((size = in.read(temp)) != -1) {
            out.write(temp, 0, size);
        }
        in.close();
        byte[] content = out.toByteArray();
        //SysHuaWeiLinux linux = new SysHuaWeiLinux();
        SysTestLinux linux = new SysTestLinux();
        String url = linux.getCustomerurl() + IdUtil.simpleUUID() + fileSuffix;
        System.out.println(url);
        customer_url = FtpUtil.sshSftp(content, IdUtil.simpleUUID() + fileSuffix);
        return R.ok().message("客资截图上传成功!!").data("url",customer_url);
    }


    /**
     * 二维码上传接口
     */
    @PostMapping(value = "/importFileEwm")
    @Log(title = "二维码上传接口", operationType = OperationType.OTHER)
    public R importFileEwm(@RequestParam("file") MultipartFile file) throws Exception {
        File toFile = null;
        if (file.equals("") || file.getSize() <= 0) {
            file = null;
        } else {
            InputStream ins = null;
            ins = file.getInputStream();
            toFile = new File(file.getOriginalFilename());
            inputStreamToFile(ins, toFile);

            ins.close();
        }
        if (file.isEmpty()) {
            return R.error().message("文件为空");
        }
        String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        FileInputStream fileInputStream = new FileInputStream(toFile);
        BufferedInputStream in = new BufferedInputStream(fileInputStream);
        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
        byte[] temp = new byte[1024];
        int size = 0;
        while ((size = in.read(temp)) != -1) {
            out.write(temp, 0, size);
        }
        in.close();
        byte[] content = out.toByteArray();
//        SysZhengshiLinux linux = new SysZhengshiLinux();
        SysTestLinux linux = new SysTestLinux();
        String url = linux.getCustomerurlewm() + IdUtil.simpleUUID() + fileSuffix;
        System.out.println(url);
        customer_ewm = FtpUtil.sshSftpEwm(content, IdUtil.simpleUUID() + fileSuffix);
        return R.ok().message("二维码上传成功!!");
    }

    //获取流文件
    private static void inputStreamToFile(InputStream ins, File file) {
        try {
            OutputStream os = new FileOutputStream(file);
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
            System.out.println(os);
            os.close();
            ins.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    //批量导出（批量修改）
    @PostMapping(path = "customerinformationexceloutput")
    @Log(title = "批量导出客资信息", operationType = OperationType.OTHER)
    public R customerinformationexceloutput(@RequestBody Map<String, String> param, HttpServletResponse response) throws MZException {
        List<CustomerInformation> list = customerInformationService.customerinformationlist(param);
        List<ExcelCustomerInformationOutData> excelVos = new ArrayList<>();
        list.forEach(customerInformation -> {
            String customerIsactive = null;
            if (customerInformation.getCustomerIsactive() == 1) {
                customerIsactive = "主动";
            } else {
                customerIsactive = "被动";
            }
            String customer_state = null;
            if (customerInformation.getCustomerState() == 1) {
                customer_state = "新课";
            } else if (customerInformation.getCustomerState() == 2) {
                customer_state = "未通过";
            } else if (customerInformation.getCustomerState() == 3) {
                customer_state = "已通过";
            } else {
                customer_state = "不存在";
            }
            excelVos.add(ExcelCustomerInformationOutData.builder()
                    .customerWx(customerInformation.getCustomerWx())
                    .customerEwm(customerInformation.getCustomerEwm())
                    .sourceName(customerInformationService.getsourcename(customerInformation.getCustomerSource()))
                    .sourcepeopleName(customerInformationService.getsourcepeoplename(customerInformation.getCustomerSourcepeople()))
                    .customerTeacherName(teacherDao.getteacherName(customerInformation.getCustomerTeacherid()))
                    .customerStudent(customerInformation.getCustomerStudent())
                    .createTime(customerInformation.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
                    .customerIsactive(customerIsactive)
                    .customerState(customer_state)
                    .build());
        });
        String fileName = "数据导出" + System.currentTimeMillis();
        try {
            ExcelUtil.export(fileName, excelVos, ExcelCustomerInformationOutData.class, response);
        } catch (Exception e) {
            throw new MZException(CodeEnum.EXCEL_DATA_EXPORT_ERROR);
        }
        return R.ok().message("模板导出成功");
    }


    /**
     * 单个查询客资
     */

    @ApiOperation(value = "单个查询客资", notes = "单个查询客资")
    @GetMapping("customersone/{customer_id}")
    @Log(title = "单个查询客资", operationType = OperationType.SELECT)
    public R customersone(@PathVariable Long customer_id) throws MZException {
        return R.ok().data("list", customerInformationService.customersone(customer_id)).message("查询成功");
    }

    /**
     * 修改客资信息
     */

    @ApiOperation(value = "修改客资信息", notes = "修改客资信息")
    @PutMapping("customerstudentupdate")
    @Log(title = "修改客资信息", operationType = OperationType.UPDATE)
    public R customerstudentupdate(@RequestBody CustomerInformationDtoTwo c) throws MZException {
        boolean a = customerInformationService.customerstudentupdate(c);
        if (a) {
            return R.ok().message("修改客资信息成功!!");
        } else {
            throw new MZException(CodeEnum.Customer_Student);
        }
    }


    /**
     * 查询销售列表
     */

    @ApiOperation(value = "查询销售列表", notes = "查询销售列表")
    @GetMapping("customersale")
 /*   @Log(title = "查询销售列表", operationType = OperationType.SELECT)*/
    public R customersale() throws MZException {
        return R.ok().data("list", customerInformationService.customersale()).message("查询销售列表成功");
    }


}
